const joi = require('joi');
const validationMiddleware = require('../../middleware/validate');
const { dealNotEmpty } = require('../../utils/dberrordeal');
const shopCarController = require('../../controllers/good/shopcarController');
const router = require('koa-router')();
router.prefix('/shopcar');
const { verify } = require('../../utils/auth');
router.use(verify);
const rulesSchema = {
    '/shopcar/addshopcar': joi.object({
        goodId: dealNotEmpty('商品id'),
        quantity: joi.number().min(1).required().messages({
            'number.base': '数量必须是数字',
            'number.min': '数量不能小于1',
            'any.required': '数量是必填字段',
        }),
        sid: dealNotEmpty('购物车分组id'),
    }),
    '/shopcar/putshopcar': joi.object({
        id: dealNotEmpty('购物车id'),
        quantity: joi.number().min(1).required().messages({
            'number.base': '数量必须是数字',
            'number.min': '数量不能小于1',
            'any.required': '数量是必填字段',
        }),
        sid: dealNotEmpty('购物车分组id'),
    }),
    '/shopcar/getshopcar': joi.object({
        id: dealNotEmpty('购物车id'),
    }),
    '/shopcar/delshopcar': joi.object({
        id: dealNotEmpty('购物车id'),
    }),
    '/shopcar/delshopcarbysid': joi.object({
        sid: dealNotEmpty('购物车分组id'),
    }),
    '/shopcar/delshopcarall': joi.object({
    }),
};
router.post('/addshopcar', validationMiddleware(rulesSchema), shopCarController.createShopCar);
router.post('/putshopcar', validationMiddleware(rulesSchema), shopCarController.updateShopCar);
router.post('/getshopcar', validationMiddleware(rulesSchema), shopCarController.getShopCarById);
router.post('/delshopcar', validationMiddleware(rulesSchema), shopCarController.deleteShopCar);
router.post('/getshopcarlist', shopCarController.getShopCarList);
router.post('/delshopcarbysid', validationMiddleware(rulesSchema), shopCarController.deleteShopCarBySid);
router.post('/delshopcarall', validationMiddleware(rulesSchema), shopCarController.deleteShopCarAll);
module.exports = router;
